(function(){

    var DayData = window.DayData = function(){

        // 网点分布图
        this.getEcharts();

        // // 动态获取地图数据
        // this.getMapData();

        // 计时期调用的一些方法
        this.timerAll();

        // 网点
        this.latticePoint();

        // 金额折线图和订单
        this.moneyOrder();

        // 用户
        this.user();

        // 订单详情
        this.OrderDetails();

        // 具体订单轮播滚动
        this.AutoScroll();

        // 定时器
        this.timer();

    };

    var window_host = "http://192.168.1.61/washcar/public/"; // url

    // 计时期调用的一些方法
    DayData.prototype.timerAll = function(){

        this.timer(this.getEcharts,180000);

        this.timer(this.AutoScroll,180000); // 具体订单轮播滚动方法

        this.timer(this.OrderDetails,180000); // 订单详情

        this.timer(this.user,180000); // 用户

        this.timer(this.moneyOrder,180000); // 金额折线图和订单

        this.timer(this.latticePoint,180000); // 网点

    };

    // 网点
    DayData.prototype.latticePoint = function(){

        $.ajax({

            // 网点
            url: window_host + 'dayBankShopTotal',

            data: {
                "top5" : 5
            },

            type:'get',

            success: function (data) {

                var newInfo = "";

                var dataobj_bankshop = typeof data === "object" ? data : eval("(" + data + ")");

                $(".top_5_inner").text("");

                for( var j = 1 ; j < dataobj_bankshop.length + 1 ; j ++ ){

                    newInfo = '<p id=' + dataobj_bankshop[j - 1].id +  ' class="backshow backshow' + j + '">TOP' + j + " " + dataobj_bankshop[j - 1].shopName + '</p><p class="backshow_box backshow_box'+j+'"></p>';

                    $(".top_5_inner").append(newInfo);

                }

            }

        });

    }; // 网点结束

    // 金额和订单
    DayData.prototype.moneyOrder = function(){

        $.ajax({

            url: window_host + 'dayOrderMoney', // 关于钱和订单

            type:'get',

            success: function (data) {

                var dataobj_money = typeof data === "object" ? data : eval("(" + data + ")");

                $(".day_money_inner").html(dataobj_money.money_today); // 今日交易金额

                $(".yesterday_money_inner").html(dataobj_money.money_yestoday); // 昨日交易金额

                $(".all_money").html(dataobj_money.money_total); // 总交易额

                $(".olderNumber_much").html(dataobj_money.order_total); // 成交订单数

                var dataArr = JSON.parse(dataobj_money.dataArr);

                var moneyArr = JSON.parse(dataobj_money.moneyArr);

                $('#container').highcharts({

                     chart: {
                             type: 'line',
                             backgroundColor: 'rgba(0,0,0,0)',
                     },
                     legend: {
                             align: 'right', //程度标的目标地位
                             itemStyle: {
                                 color: 'rgba(255,255,255,0.6)'
                             },
                             verticalAlign: 'top', //垂直标的目标地位
                             x: 0, //间隔x轴的间隔
                                 // y: 100 //间隔Y轴的间隔
                    },
                     colors:[
                         '#1cfeb6'
                     ],
                     title: {
                         text: '日交易金额-折线图',
                         y: 20, //x轴刻度往下移动20px
                         style: {
                             color: '#3ad1ff',
                             fontSize: '.22rem'
                         }
                     },
                     xAxis: {
                         categories: dataArr,
                            // tickColor:'#2faef5',
                         lineColor:'#2faef5',
                         tickWidth:0,
                         labels: {
                             y: 20, //x轴刻度往下移动20px
                             style: {
                                 color: 'rgba(255,255,255,0.6)',//颜色
                                 fontSize: '.14rem',  //字体
                                 fontFamily:'arial',
                             }
                         }
                     },
                     yAxis: {
                         gridLineColor:'rgba(47,174,245,.28)',
                         title: {
                             text: '金额',
                             style: {
                                 color: 'rgba(255,255,255,.3)',
                                 fontSize: '.12rem'
                             }
                         },
                         labels: {
                             style: {
                                 color: 'rgba(255,255,255,0.6)',//颜色
                                 fontSize: '.14rem',  //字体
                                 fontFamily:'arial'
                             }
                         }

                     },
                     // plotOptions: {
                     //     line: {
                     //         dataLabels: {
                     //             enabled: true          // 开启数据标签
                     //         },
                     //         enableMouseTracking: false // 关闭鼠标跟踪，对应的提示框、点击事件会失效
                     //     }
                     // },
                     tooltip: {
                         valueSuffix: '元'
                     },
                     series: [
                         {
                             name: '收入金额',
                             data:  moneyArr
                         }
                     ]

                 });

            }

        });

    }; // 金额订单end

    // 用戶
    DayData.prototype.user = function(){

        $.ajax({

            url: window_host + 'dayRegisterTotal',

            type:'get',

            success: function (data) {

                var dataobj_user = typeof data === "object" ? data : eval("(" + data + ")");

                $(".allTotal_much").html(dataobj_user.register_total); // 今日交易金额
            }

        });
    }; // 用户end

    // 订单详情
    DayData.prototype.OrderDetails = function(){

        $.ajax({

            // 交易详情
            url: window_host + 'dayOrderInfo',

            type:'get',

            success:function(data){

                var orderInfo = "";

                var dataobj_info = typeof data === "object" ? data : eval("(" + data + ")");

                $(".specific_order_info").text(""); // 请求前清空循环内容

                for( var j = 0 ; j < dataobj_info.infoList.length ; j ++ ){

                    var Phone = dataobj_info.infoList[j].phone;

                    var carCode = dataobj_info.infoList[j].car_code;

                    var orderMoney = dataobj_info.infoList[j].order_money;

                    var classStr = "background_135";

                    if( j % 2 == 0 ){
                        classStr ="background_135";
                    }else{
                        classStr ="background_246";
                    }

                    orderInfo = '<div class="specific_order_info_inner '+classStr+'"><p class="order_info order_info_phone">'+Phone+'</p><p class="order_info order_info_plate">'+carCode+'</p><p class="order_info order_info_money">'+orderMoney+'</p></div>';

                    $(".specific_order_info").append(orderInfo);
                }

            }

        });

    }; // 订单详情end

    // 定时器一些方法
    DayData.prototype.timer = function(fun,times){

        setInterval(fun,times);

    };

    // 具体订单轮播滚动方法
    DayData.prototype.AutoScroll = function(){

        if($(".specific_order_info .specific_order_info_inner").length > 6){

            $(".specific_order_info").animate({marginTop: "-.45rem"},700,function() {

                $(this).css({ marginTop: "0rem" }).find(".specific_order_info_inner:first").appendTo(this);

            });
        }

    };

    // // 动态获取地图数据
    // DayData.prototype.getMapData = function(){

    //     var self = this;

    //     $.ajax({

    //         url: window_host + 'bankShopMap',
    //         // url: 'abc.json',

    //         success: function (data) {

    //             var dataobj_user = typeof data === "object" ? data : eval("(" + data + ")");

    //             console.log(dataobj_user.geo_coord_map);
    //             // console.log(dataobj_user.line_value);
    //             // console.log(dataobj_user.point_value);

    //             self.getEcharts(dataobj_user.geo_coord_map,dataobj_user.line_value,dataobj_user.point_value);

    //         }

    //     });
    // }

    // 网点分布图
    DayData.prototype.getEcharts = function(){

        $.ajax({

            url: window_host + 'bankShopMap',

            success: function (data) {

                var dataobj_user = typeof data === "object" ? data : eval("(" + data + ")");
                console.log(typeof dataobj_user.line_value);
                var geo_coord_map = typeof dataobj_user.geo_coord_map === "object" ? dataobj_user.geo_coord_map : eval("(" + dataobj_user.geo_coord_map + ")");
                var line_value = typeof dataobj_user.line_value === "object" ? dataobj_user.line_value : eval("(" + dataobj_user.line_value + ")");
                var point_value = typeof dataobj_user.point_value === "object" ? dataobj_user.point_value : eval("(" + dataobj_user.point_value + ")");


                console.log(typeof line_value);

                require.config({
                    paths: {
                        echarts: './js'
                    }
                });

                require(
                    [
                        'echarts',
                        'echarts/chart/map'
                    ],
                    function (ec) {
                        // --- 地图 ---
                        var myChart2 = ec.init(document.getElementById('mainMap'));
                        myChart2.setOption({
                            series : [
                                {
                                    name: '全国',
                                    type: 'map',
                                    roam: true,
                                    hoverable: false,
                                    mapType: '陕西|西安市',
                                    roam: true,
                                    itemStyle:{
                                        normal:{
                                            label:{show:true},
                                            borderWidth:1,
                                            areaStyle:{
                                                color: 'rgba(58, 202, 246,0)',
                                            }
                                        },
                                    },

                                    data:[
                                        {name: '西安市',value: Math.round(Math.random()*1000)},
                                    ],
                                    markLine : {
                                        smooth:true,
                                        effect : {
                                            show: true,
                                            scaleSize: 1,
                                            period: 20,
                                            color: 'orange',
                                            shadowBlur: 5
                                        },
                                        symbol: ['none', 'circle'],
                                        itemStyle : {
                                            normal: {
                                                borderWidth:1,
                                                lineStyle: {
                                                    color:'yellow',
                                                    opacity: 0.6,
                                                    curveness: 0.2,
                                                    width: 1,
                                                }
                                            }
                                        },
                                        // data : line_value
                                        data : [
                                            [{name:'西安'},{name:'周至',value:''}],
                                            [{name:'西安'},{name:'临潼',value:''}],
                                            [{name:'西安'},{name:'蓝田',value:''}],
                                            [{name:'西安'},{name:'鄠邑区',value:''}],
                                            [{name:'西安'},{name:'陕西省西安市长安区王曲街道238乡道',value:''}],
                                        ]
                                        // data : [
                                        //     [{name:'西安'},{name:'中国石化加油站(红光路)',value:''}],
                                        //     [{name:'西安'},{name:'延长壳牌加油站(太白路立交东)',value:''}],
                                        //     [{name:'西安'},{name:'中国石油加油站(西万路)',value:''}],
                                        //     [{name:'西安'},{name:'中国石油加油站(西门)',value:''}],
                                        // ]

                                    },
                                    // geoCoord: geo_coord_map,
                                    geoCoord: {
                                        '咸阳': [108.4131,34.8706],
                                        '宝鸡': [107.1826,34.3433],
                                        '延安': [109.1052,36.4252],
                                        '渭南': [109.7864,35.0299],
                                        '西安': [108.906489,34.240068],
                                        '安康': [109.029022,32.684714],
                                        '高陵': [108.862524,34.163328],
                                        '蓝田': [109.323479,34.151624],
                                        '临潼': [109.214238,34.367275],
                                        '周至': [108.222154,34.163621],
                                        '鄠邑区': [108.626575,34.093558],
                                        '新城区西影路': [108.874913,34.230797],
                                        '未央区明光路': [108.940174,34.341568],
                                        '雁塔区劳动南路': [108.874913,34.230797],
                                        '陕西省西安市周至县集贤镇科技大道1号': [108.386383,34.066757],
                                        '陕西省西安市长安区王曲街道238乡道': [108.962251,34.09397]
                                    },
                                    // geoCoord: {
                                    //     '西安': [108.906489,34.240068],
                                    //     '中国石化加油站(红光路)': [108.843098,34.258663],
                                    //     '延长壳牌加油站(太白路立交东)': [108.923538,34.235641],
                                    //     '中国石油加油站(西万路)': [108.903802,34.206988],
                                    //     '中国石油加油站(西门)': [108.927851,34.276899]
                                    // },
                                    markPoint : {
                                        symbol:'emptyCircle',
                                        symbolSize : function (v){
                                            return 10 + v/10
                                        },
                                        effect : {
                                            show: true,
                                            shadowBlur : 0,
                                            color:'yellow'
                                        },
                                        itemStyle:{
                                            normal:{
                                                label:{show:false}
                                            },
                                            emphasis: {
                                                label:{position:'top'}
                                            }
                                        },
                                        data : [
                                            {name:'周至',value:''},
                                            {name:'临潼',value:''},
                                            {name:'蓝田',value:''},
                                            {name:'鄠邑区',value:''},
                                            {name:'陕西省西安市长安区王曲街道238乡道',value:''},
                                        ]
                                        // data : point_value
                                        // data : [
                                        //     {name:'中国石化加油站(红光路)',value:''},
                                        //     {name:'延长壳牌加油站(太白路立交东)',value:''},
                                        //     {name:'中国石油加油站(西万路)',value:''},
                                        //     {name:'中国石油加油站(西门)',value:''}
                                        // ]
                                    }
                                }
                            ]
                        });
                    }
                );


            }

        });


    };

})();